package com.example.my.myapplication;

import android.app.Activity;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}
    public void class Main extends Activity{
    private Button btn_StartService;
    private Button bth_StopService;
    private Button bth_BindService;
    private Button bth_UnbindService;
    private ServiceConnection mServiceConnection;
    private View bth_StartService;


    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setupViews();
        mServiceConnection = new ServiceConnection() {
            @Override
            public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            }
            @Override
            public void onServiceDisconnected(ComponentName componentName) {
            }
        };
    }
    public void setupViews() {
        btn_StartService = (Button) findViewById(R.id.imageButton1);
        bth_StopService = (Button) findViewById(R.id.imageButton2);
        bth_BindService = (Button) findViewById(R.id.imageButton3);
        bth_UnbindService = (Button) findViewById(R.id.imageButton4);

        bth_StartService.setOnClickListener(new DialogInterface.OnClickListener(){
            public void onClick(View view){
                Intent intent = new Intent(Main.this, MyService.class);
                startService(intent);
            }
        });
        bth_StopService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Main.this,MyService.class);
                stopService(intent);
            }
        });
        bth_BindService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Main.this,MyService.class);
                bindService(intent, mServiceConnection, BIND_AUTO_CREATE);
            }
        });
        bth_UnbindService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                unbindService(mServiceConnection);
            }
        });
    }
    protected void onDestroy(){

    }
}